﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using TTSIDAL;
using TTSModel;

namespace TTSDAL
{
    public class KCCSNUnion : BaseRepository<KCCSNUnionInfo>, IKCCSNUnion
    {
        #region 静态变量定义
        private const string PARM_KCCSNUNION_KCCSN1 = "@KCCSN1";
        private const string PARM_KCCSNUNION_KCCSN2 = "@KCCSN2";
        private const string PARM_KCCSNUNION_SN = "@SN";
        private const string PARM_KCCSNUNION_USERID = "@UserID";
        #endregion

        #region 数据检索部分
        public IList<KCCSNUnionInfo> LoadEntities()
        {
            return null;
        }

        public KCCSNUnionInfo LoadEntity<T1>(T1 sn)
        {
            SqlParameter parm = GetParameter();
            parm.Value = sn;
            return ExcuteSqlToGetEntity("KCCSNUnion_selectbySN", parm);
        }

        public KCCSNUnionInfo KCCSNUnion_GetbyKCCSN1(string sn)
        {
            SqlParameter parm = new SqlParameter(PARM_KCCSNUNION_KCCSN1, SqlDbType.NVarChar, 50); 
            parm.Value = sn;
            return ExcuteSqlToGetEntity("KCCSNUnion_selectbyKCCSN1", parm);
        }
        public KCCSNUnionInfo KCCSNUnion_GetbySN(string sn)
        {
            SqlParameter parm = new SqlParameter(PARM_KCCSNUNION_SN, SqlDbType.NVarChar, 50);
            parm.Value = sn;
            return ExcuteSqlToGetEntity("KCCSNUnion_selectbySN", parm);
        }
        public void KCCSNUnion_DeletebyKCCSN1(string sn,string storeprodecure)
        {
            SqlParameter parm = new SqlParameter(PARM_KCCSNUNION_KCCSN1, SqlDbType.NVarChar, 50);
            parm.Value = sn;
            SqlCommand cmd = new SqlCommand();
            cmd.Parameters.Add(parm);
            try
            {
                ExecuteCommand(cmd, storeprodecure);
            }
            catch
            {
                throw;
            }
        }



        #endregion

        #region 重写基类方法
        public override KCCSNUnionInfo GetEntityRecord(SqlDataReader rdr)
        {
            KCCSNUnionInfo entity = new KCCSNUnionInfo()
            {
                KCCSN1 = rdr.GetValue(0).ToString(),
                KCCSN2 = rdr.GetValue(1).ToString(),
                SN = rdr.GetValue(2).ToString(),
                UserID = rdr.GetValue(3).ToString()
            };
            return entity;
        }

        public override KCCSNUnionInfo GetEntityRecord()
        {
            KCCSNUnionInfo entity = new KCCSNUnionInfo();
            return entity;
        }

        public override string GetInsertsp()
        {
            return "KCCSNUnion_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_KCCSNUNION_SN, SqlDbType.NVarChar, 50);
            return parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter(PARM_KCCSNUNION_KCCSN1,SqlDbType.NVarChar,50),
                new SqlParameter(PARM_KCCSNUNION_KCCSN2,SqlDbType.NVarChar,50),
                new SqlParameter(PARM_KCCSNUNION_SN,SqlDbType.NVarChar,50),
                new SqlParameter(PARM_KCCSNUNION_USERID,SqlDbType.NVarChar,6),  
            };
            return parms;
        }

        public override void SetParameters(KCCSNUnionInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.KCCSN1;
            Parms[1].Value = Entity.KCCSN2;
            Parms[2].Value = Entity.SN;
            Parms[3].Value = Entity.UserID;
        }
        #endregion
    }
}
